<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  /**
   * 贺鹏
   * @param fn
   * @returns fun1
   */
  function fun(fn) {
    // 参数的数量
    if (fn.length <= 1) return fn;
    //
    const fun1 = (...args1) => {
      if (fn.length === args1.length) {
        return fn(...args1)
      } else {
        return (...args2) => {
          return fun1(...args1, ...args2)
        }
      }
    };
    return fun1
  }

  function add(n1, n2, n3, n4, n5) {
    return n1 + n2 + n3 + n4 + n5
  }

  let zhaomengfan = fun(add);
  console.log(zhaomengfan(1)(2)(3)(4)(5));
</script>
</body>
</html>
